package com.twu.biblioteca.librarycollection;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Maximilian
 * Date: 3/10/13
 * Time: 10:03 AM
 * To change this template use File | Settings | File Templates.
 */
class MovieFormatter {

    protected static String generateFormattedMovieList(List<MovieCollection.Movie> movies)
    {
        String movieString = "";

        int titleLen = "Title".length(), directorLen = "Director".length();

        for(MovieCollection.Movie movie : movies)
        {
            if(movie.name.length() > titleLen)
                titleLen = movie.name.length();
            if(movie.director.length() > directorLen)
                directorLen = movie.director.length();
        }

        movieString = pad("Title", titleLen) + " | " + "Year" + " | " + pad("Director", directorLen) + " | " + "Rating" + "\n";
        movieString += printChar('*', 12 + 4 + titleLen + directorLen + 10) + "\n";

        for(MovieCollection.Movie movie : movies)
        {
            movieString += pad(movie.name, titleLen) + " | " + movie.year + " | " + pad(movie.director, directorLen) + " | " + genRatingStr(movie.rating) + "\n";
        }

        return movieString;
    }

    private static String pad(String text, int pamount)
    {
        String t = "";
        t = text;
        for(int i = 0; i < pamount - text.length(); i++)
        {
            t += " ";
        }
        return t;
    }

    private  static String printChar(char c, int nr)
    {
        String str = "";
        for(int i = 0; i < nr; i++)
        {
            str += c;
        }
        return str;
    }

    private static String genRatingStr(int rating)
    {
        String str = "";
        for(int i = 0; i < rating; i++)
        {
            str += "o";
        }
        return str;
    }
}
